<template>
  <div class="left-float-banner" @click.stop="visible = true" v-if="!visible && showBanner">
    <button class="close-btn" @click.stop="closeBanner">×</button>
    <div class="banner-content">
      <slot>
        UP TO $10 OFF
      </slot>
    </div>
  </div>
  <div class="modal-mask" v-if="visible">
    <div class="modal-container">
      <button class="modal-close" @click="close">×</button>
      <div class="modal-left">
        <img src="https://d3k81ch9hvuctc.cloudfront.net/company/VEs2cd/images/63431cc7-219e-4a58-b738-f0cce43996fb.jpeg"
          alt="promo" />
      </div>
      <div class="modal-right">
        <div class="brand">
          <img alt="GOELIA" class="logo"
            src="https://d3k81ch9hvuctc.cloudfront.net/company/VEs2cd/images/2c44e211-ea33-4430-b734-b6e1cfe88da8.png" />
        </div>
        <h4>WELCOME TO GOELIA!</h4>
        <h2>ENJOY UP TO $10 OFF</h2>
        <p style="color: #000;font-size: 16px;">Subscribe to our newsletter and get up to $10 off.</p>
        <input v-model="email" type="email" placeholder="Enter Email*" class="modal-input" />
        <button class="modal-btn" @click="claim">CLAIM NOW</button>
        <div class="modal-tip">
          *By subscribing, you agree to our <a href="#">Terms & Conditions</a> and <a href="#">Privacy Policy</a>.You
          can unsubscribe at any time.
        </div>
      </div>
    </div>
  </div>
  <a-modal v-model:visible="emailVisible" title="Verify your email" @ok="handleOk" :footer="null">
    <VerifyEmail :email=email @dialogVisible="handleDialogVisible" />
  </a-modal>
</template>

<script setup lang="ts">
import { ref } from 'vue'

import VerifyEmail from "@/components/VerifyEmail.vue"


const visible = ref(false)
const emailVisible = ref(false)
const showBanner = ref(true)

const email = ref('')
function close() {
  visible.value = false
}

function closeBanner() {
  showBanner.value = false
}

const handleOk = (e: MouseEvent) => {
  emailVisible.value = false;
};
const claim = async () => {
  emailVisible.value = true
  visible.value = false
  // 这里可以加邮箱校验和提交逻辑
  // alert('Claimed: ' + email.value)
  // const res = await postVerifyEmail({email:email.value})
  // if(res.data == 200){
  //   message.success('Email verification successful')
  //   visible.value = false
  // }else{
  //   message.error('Email verification failed')
  // }
}
// 处理弹框显示和隐藏
const handleDialogVisible = (visible) => {
  emailVisible.value = visible;
};
</script>

<style scoped>
.left-float-banner {
  position: fixed;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9999;
  background: #222;
  color: #fff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  padding: 0;
  min-width: 48px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.banner-content {
  writing-mode: vertical-rl;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 2px;
  padding: 24px 8px 16px 8px;
}

.close-btn {
  position: absolute;
  top: -8px;
  left: 20%;
  transform: translateX(-50%);
  background: #444;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 18px;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-mask {
  position: fixed;
  z-index: 2000;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-container {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  display: flex;
  max-width: 780px;
  width: 90vw;
  min-height: 400px;
  position: relative;
  overflow: hidden;
}

.modal-close {
  position: absolute;
  top: -4px;
  right: 13px;
  background: none;
  border: none;
  font-size: 26px;
  color: #888;
  cursor: pointer;
  z-index: 2;
}

.modal-left {
  flex: 1.1;
  min-width: 260px;
  background: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-left img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-right {
  flex: 1.3;
  padding: 60px 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
  justify-content: center;
}

.logo {
  height: 32px;
}

.anniversary {
  font-size: 18px;
  font-weight: bold;
}

h4 {
  color: #b48b5a;
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 500;
}

h2 {
  margin: 0 0 12px 0;
  font-size: 24px;
  font-weight: bold;
  color: #222;
}

p {
  margin: 0 0 18px 0;
  color: #444;
  font-size: 15px;
}

.modal-input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-size: 15px;
}

.modal-btn {
  width: 100%;
  background: rgb(157, 118, 104);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 12px 0;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  margin-bottom: 10px;
}

.modal-btn:hover {
  background: #a07a4a;
}

.modal-tip {
  font-size: 12px;
  color: #888;
  margin-top: 8px;
}

.modal-tip a {
  /* color: #b48b5a; */
  text-decoration: underline;
}
</style>